package com.shareach.domain;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.Document;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.shareach.util.Globals;

@Document(collection = "bankCollect")
public class BankCollectDomain {
	@Id
	private String url;
	private String bank;
	private String pageUrl;
	private Date time;
	private Date processTime;
	private String remark;
	private String title;
	// 0-未处理 1-已采用 2-已抛弃s
	private Integer status;

	@Transient
	private List<String> fieldExists;
	@Transient
	private List<String> fieldNoneExists;
	@Transient
	private Map<String, String> dateSearchMap;

	public void addDateMap(String k, String v) {
		if (null == this.dateSearchMap) {
			this.dateSearchMap = Maps.newHashMap();
		}
		this.dateSearchMap.put(k, v);
	}

	public Map<String, String> getDateSearchMap() {
		return dateSearchMap;
	}

	public void setDateSearchMap(Map<String, String> dateSearchMap) {
		this.dateSearchMap = dateSearchMap;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public void addFieldExists(String propName) {
		if (null == this.fieldExists) {
			this.fieldExists = Lists.newArrayList();
		}
		this.fieldExists.add(propName);
	}

	public void addFieldNoneExists(String propName) {
		if (null == this.fieldNoneExists) {
			this.fieldNoneExists = Lists.newArrayList();
		}
		this.fieldNoneExists.add(propName);
	}

	public List<String> getFieldExists() {
		return fieldExists;
	}

	public List<String> getFieldNoneExists() {
		return fieldNoneExists;
	}

	public void setFieldExists(List<String> fieldExists) {
		this.fieldExists = fieldExists;
	}

	public void setFieldNoneExists(List<String> fieldNoneExists) {
		this.fieldNoneExists = fieldNoneExists;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getBank() {
		return bank;
	}

	public String getPageUrl() {
		return pageUrl;
	}

	public Date getProcessTime() {
		return processTime;
	}

	public String getRemark() {
		return remark;
	}

	public Date getTime() {
		return time;
	}

	public String getUrl() {
		return url;
	}

	public void setBank(String bank) {
		this.bank = bank;
	}

	public void setPageUrl(String pageUrl) {
		this.pageUrl = pageUrl;
	}

	public void setProcessTime(Date processTime) {
		this.processTime = processTime;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public void setTime(Date time) {
		this.time = time;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public BankCollectDomain compareTo(BankCollectDomain domain) {
		BankCollectDomain change = new BankCollectDomain();
		if (null == domain)
			return change;
		if (StringUtils.isNotEmpty(domain.url)) {
			if (this.url == null || !this.url.trim().equals(domain.getUrl().trim())) {
				change.setUrl(domain.getUrl().trim());
			}
		}
		if (StringUtils.isNotEmpty(domain.getBank())) {
			if (this.bank == null || !this.bank.trim().equals(domain.getBank().trim())) {
				change.setBank(domain.getBank().trim());
			}
		}
		if (StringUtils.isNotEmpty(domain.getPageUrl())) {
			if (this.pageUrl == null || !this.pageUrl.trim().equals(domain.getPageUrl().trim())) {
				change.setPageUrl(domain.getPageUrl().trim());
			}
		}
		if (StringUtils.isNotEmpty(domain.getRemark())) {
			if (this.remark == null || !this.remark.trim().equals(domain.getRemark().trim())) {
				change.setRemark(domain.getRemark().trim());
			}
		}
		if (domain.getTime() != null) {
			if (this.time != null) {
				if (!Globals.FORMAT_TYPE_A.format(this.time).equals(Globals.FORMAT_TYPE_A.format(domain.getTime()))) {
					change.setTime(domain.getTime());
				}
			} else {
				change.setTime(domain.getTime());
			}
		}
		if (domain.getProcessTime() != null) {
			if (this.processTime != null) {
				if (!Globals.FORMAT_TYPE_A.format(this.processTime).equals(
						Globals.FORMAT_TYPE_A.format(domain.getProcessTime()))) {
					change.setProcessTime(domain.getProcessTime());
				}
			} else {
				change.setProcessTime(domain.getProcessTime());
			}
		}
		return change;
	}
}
